﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.17
 * 描 述：元数据导入
 */
var refreshGirdData; // 更新数据
var selectedRow;

var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.bind();
            page.initGrid();
            page.search();
        },
        bind: function () {
            // 搜索框初始化
            $('#txt_Keyword').on("keypress", function (e) {
                if (event.keyCode == "13") {
                    var $this = $(this);
                    var keyword = $this.val();
                    page.search({keyword: keyword});
                }
            });
            // 公司选择
            $('#companyId').lrselect({
                type: 'tree',
                placeholder: '==请选择单位==',
                height: 300,
                maxHeight: 300,
                // 是否允许搜索
                allowSearch: true,
            });
            $('#companyId').lrselectRefresh({
                // 访问数据接口地址
                url: config.base_server() + 'companys/tree?access_token=' + config.getToken().access_token,
                // 访问数据接口参数
                param: {parentId: '0'}
            });

            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#txt_Keyword').val();
                page.search({keyword: keyword});
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                selectedRow = null;
                learun.layerForm({
                    id: 'Form',
                    title: '添加模型',
                    url: config.webportal_server + 'pages/finance/source_file_import/form.html?access_token=' + config.getToken().access_token,
                    width: 750,
                    height: 580,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                var keyValue = $('#gridtable').jfGridValue('id');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'Form',
                        title: '编辑模型',
                        url: config.webportal_server + 'pages/finance/source_file_import/form.html?access_token=' + config.getToken().access_token,
                        width: 750,
                        height: 580,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('id');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('该动作执行后此项将彻底被删除，是否确认删除该项?', function (res) {
                        if (res) {
                            learun.deleteForm(config.base_server() + 'sourcefileimports/delete/' + keyValue + '?access_token=' + config.getToken().access_token, {keyValue: keyValue}, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });
            // 数据导出
            $('#lr_export').on('click', function () {
                location.href = config.base_server() + 'companyexcel/export?access_token=' + config.getToken().access_token;
            });
        },
        initGrid: function () {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'sourcefileimports/list?access_token=' + config.getToken().access_token,
                headData: [
                    {label: "所属单位", name: "companyName", width: 180, align: "left"},
                    {label: "会计年度", name: "kjnd", width: 70, align: "center"},
                    {
                        label: "导入方式", name: "importWay", width: 70, align: "center",
                        formatter: function (cellvalue) {
                            if (cellvalue == "1") {
                                return "全量";
                            } else if (cellvalue == "2") {
                                return "增量";
                            }
                        }
                    },
                    {
                        label: "公务用车", name: "usecarXls", width: 80, align: "center",
                        formatter: function (cellvalue) {
                            if (cellvalue != '') {
                                return "√";
                            }
                        }
                    },
                    {
                        label: "预算执行情况", name: "budgetexcuteXls", width: 90, align: "center",
                        formatter: function (cellvalue) {
                            if (cellvalue != '') {
                                return "√";
                            }
                        }
                    },
                    {
                        label: "预算申报情况", name: "budgettotalXls", width: 90, align: "center",
                        formatter: function (cellvalue) {
                            if (cellvalue != '') {
                                return "√";
                            }
                        }
                    },
                   {
                        label: "决算报表汇总", name: "finalaccountXls", width: 90, align: "center",
                        formatter: function (cellvalue) {
                            if (cellvalue != '') {
                                return "√";
                            }
                        }
                   },
                    {
                        label: "会议酒店", name: "hoteldataXls", width: 90, align: "center",
                        formatter: function (cellvalue) {
                            if (cellvalue != '') {
                                return "√";
                            }
                        }
                    },
                    {
                        label: "资产明细表", name: "assetdataXls", width: 90, align: "center",
                        formatter: function (cellvalue) {
                            if (cellvalue != '') {
                                return "√";
                            }
                        }
                    },
                    {
                        label: "资产综合统计表", name: "assettotalXls", width: 90, align: "center",
                        formatter: function (cellvalue) {
                            if (cellvalue != '') {
                                return "√";
                            }
                        }
                    },
                    {
                        label: "导入时间", name: "updateTime", width: 140, align: "center",
                        formatter: function (value) {
                            return learun.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
                        }
                    },
                    {
                        label: "导入进度", name: "importProcess", width: 70, align: "center",
                        formatter: function (cellvalue) {
                            if (cellvalue == '1') {
                                return "<span style='color: green'>成功</span>";
                            } else if (cellvalue == '-1') {
                                return "<span style='color: red'>失败</span>";
                            } else {
                                return "<span style='color: blue'>进行中</span>";
                            }
                        }
                    },
                    // {label: "备注", name: "description", width: 80, align: "left"},
                    // { label: "审计思路", name: "remark", width: 80, align: "left"}
                ],
                dblclick: function (row) {
                    selectedRow = $('#gridtable').jfGridGet('rowdata');
                    var keyValue = row;
                    if (learun.checkrow(keyValue)) {
                        learun.layerForm({
                            id: 'Form',
                            title: '编辑源文件导入',
                            url: config.webportal_server + 'pages/finance/source_file_import/form.html?access_token=' + config.getToken().access_token,
                            width: 750,
                            height: 580,
                            callBack: function (id) {
                                return top[id].acceptClick(refreshGirdData);
                            }
                        });
                    }
                },
                isTree: false,
                isPage: true,
                mainId: 'id',
            });
            page.search();
        },
        search: function (param) {
            param = param || {};
            var companyId = $("#companyId").lrselectGet();
            var kjnd = $("#kjnd").val();
            param.companyId = companyId;
            param.kjnd = kjnd;
            $('#gridtable').jfGridSet('reload', param);
        }
    };

    // 保存数据后回调刷新
    refreshGirdData = function () {
        page.search();
    }

    page.init();
}


